﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using HGZP.BLL;


namespace Admin
{
    public partial class Top : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                navi_index.InnerHtml = getMenu();
               // ltlLetterCount.Text = getLettetCount();
                //this.name.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);
            }
        }

        /// <summary>
        /// 获取未读私信数量
        /// </summary>
        /// <returns></returns>
        private string getLettetCount()
        {
/*            string _strLetterCount;
            CPrivateLetterBLL letterBll = new CPrivateLetterBLL();
            _strLetterCount = "0";
            _strLetterCount = letterBll.F09_GetCount(letterBll.sReceiver + "='" + Session["UserId"] + "' AND " + letterBll.nStatus + "='0'").ToString();
            return _strLetterCount;*/
            return "0";
        }

        /// <summary>
        /// 得到导航菜单
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        protected string getMenu()
        {
            string liststr = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">\r";
            liststr += "<tr align=\"left\"><td width=\"6\" height=\"38\"></td>";
            BaseUserBLL baseuser = new BaseUserBLL();
            System.Data.DataTable dtMenu = baseuser.GetUserFunction(Session["UserId"].ToString());
            CInfoMenuBLL infoMenu = new CInfoMenuBLL();
            System.Data.DataRow[] drMenuList = dtMenu.Select(string.Format("{0}='{1}'", infoMenu.sParentGuid, "0"));
            if (drMenuList != null && drMenuList.Length > 0)
            {
                foreach (System.Data.DataRow drMenu in drMenuList)
                {
                    liststr += checkPr("B001", drMenu[infoMenu.sGuid].ToString(), drMenu[infoMenu.sFeaturesURL].ToString(), drMenu[infoMenu.sCaption].ToString());
                }
            }
            liststr += "</td>";
            liststr += "<td></td></tr></table>";
            return liststr;
        }

        /// <summary>
        /// 权限判断
        /// </summary>
        /// <param name="code">权限代码</param>
        /// <returns></returns>
        public string checkPr(string code, string ID, string href, string Name)
        {
            string str = string.Empty;
            if (code == "B001")
            {
                str += "<td class=\"button_down\" style=\"width:82px;padding-left:14px;background-repeat:no-repeat;text-align:left;cursor:pointer;\"><a href=\"menu.aspx?Type=" + ID + "\" target=\"menu\"  >" + Name + "</a></td>";
            }
            else if (code == "B006")
            {
                str += "<td class=\"button_down\" style=\"width:82px;padding-left:14px;background-repeat:no-repeat;text-align:left;cursor:pointer;\"><a href=\"menu.aspx?Type=" + ID + "\" target=\"menu\"  >" + Name + "</a></td>";
            }
            else
            {
                str += "<td class=\"button_down\" style=\"width:82px;padding-left:14px;background-repeat:no-repeat;text-align:left;cursor:pointer;\"><a href=\"menu.aspx?Type=" + ID + "\" target=\"menu\" >" + Name + "</a></td>";
            }

            return str;
        }
    }
}